%loadPtable
%   This function creates the reference cell 'symbol' that contains all
%   current 118 "stable" elements and the asterisk "atom" that can be used
%   in SMILES. Most of the elements are loaded from the file 'ptable.mat'
%   which has been obtained from:
%   http://mvhs.shodor.org/activities/chemistry/periodicf/ptableindex.html

%%

function loadPtable
%This function creates the reference cell 'symbol' that contains all
%current 118 'known' elements and the asterisk 'atom' that can be used in
%SMILES
%Loading the element symbols from ptable.mat which we have from:
%http://mvhs.shodor.org/activities/chemistry/periodicf/ptableindex.html
%%
if exist('.\Core\temp\symbol.mat','file') == 2
    %Do nothing, all is fine
elseif exist('ptable.mat','file') == 2
    %% Load symbols from a file
    load ptable.mat % Loads ptable.mat
    symbol = cell(length(Symbol),1); % and stores all symbols in a variable
    for j = 1:length(Symbol)
        if Symbol(j,2) ~= ' '
            symbol{j,1} = Symbol(j,:);
        else
            symbol{j,1} = Symbol(j,1);
        end
    end
    %% Add new atoms
    % adds new symbols for the atoms which weren't listed in the file
    newAtoms = {'Rf' 'Db' 'Sg' 'Bh' 'Hs' 'Mt' 'Ds' 'Rg' 'Cn' 'Uut' 'Fl'...
        'Uup' 'Lv' 'Uus' 'Uuo' '*'};
    for j = 1:length(newAtoms)
        symbol{j+103,1} = newAtoms{j};
    end
    % Saves all symbols in temp dir.
    save('.\Core\temp\symbol.mat','symbol')
else
    error(['The needed files "ptable.mat" and "symbol.mat" have not' ...
        ' been found. Without either of these files this function' ...
        ' cannot run.'])
end
%%
end